Loading rulebases and rule modules in the Determinations Engine

Load rulebases and rule modules in the Determinations Engine

The following information details how to load rulebases and rulebases that rely on modules, in the Determinations Engine.

The basics of loading a rulebase

The Determinations Engine provides the following two methods for loading a rulebase:

  1. File based: Rulebases can be loaded by specifying a path to the rulebase archive on the local file system.
  2. Stream based: Allows rulebases to be loaded by providing an InputStream to the rulebase archive. This can be used to load rulebases from remote file systems, databases or other storage.

File based rulebase loading sample

String rulebasePath = "/path/to/my/rulebase.zip";
Engine engine = Engine.INSTANCE;
Rulebase rulebase = engine.getRulebase(rulebasePath);

Stream based rulebase loading sample

String rulebasePath = "/path/to/my/rulebase.zip";
FileInputStream rulebaseStream = new

FileInputStream(rulebasePath); Engine engine = Engine.INSTANCE;
Rulebase rulebase = engine.getRulebase(rulebaseStream);

Load a rulebase that references a module

Unlike a standard rulebase where the entire definition of the rulebase is contained in a single archive, a rulebase that uses modules has its definition spread over multiple archives (the rulebase archive plus a separate archive for each module it references).

In order for the rulebase to be loaded correctly, the Determinations Engine must be able to find and load each module; the responsibility for this is given to the ModuleResolver.

Loading a rulebase that relies on a module is similar to loading standard rulebase; the appropriate Engine.getRulebase(...) method is called and supplies either the path to the rulebase archive or the archive itself as a stream. Additionally, it supplies a ModuleResolver which is responsible for locating and providing the required module archive.

If a rulebase containing module references is loaded by supplying a path to the rulebase only (see the File rulebase loading sample above), then the engine will attempt to find and load any dependent modules from the same directory as the rulebase archive was loaded in. However, if a rulebase that references modules is loaded from an input stream, the caller must supply a ModuleResolver, otherwise the rulebase will fail to load.

The default implementation of the ModuleResolver provided by the Determinations Engine is the FileModuleResolver, that searches for modules in the specified directory on the local file system. Third parties may provide custom module resolution behavior by creating a class that implements ModuleResolver.

Example ModuleResolver

The following module sample illustrates how to write a custom ModuleResolver to load modules from a database. In this specific example, the rulebase, and its associated module is located in a simple Derby database. To run the supplied compiled example:

  1. Create and configure the database according to the instructions in the Rulebase Resolver - sample code (DerbyRulebaseResolver) example.
  2. Load the IncomeSupportBenefit into the database (this can be done using the BlobInsert sample in the Rulebase Resolver - sample code (DerbyRulebaseResolver).
  3. Copy the Determinations Engine and its dependencies to your deployment directory.
  4. Copy the Derby client library to your deployment directory.
  5. Run the jar file from the command line; for example:
    java -jar <jar file name>

 

See also:

Rulebase Resolver - sample code (DerbyRulebaseResolver)